<template>
  <div class="check-list">
    <van-cell>
      <van-row>
        <van-col span="12">总分：{{templateInfo.TemplateScore}}</van-col>   
        <van-col span="12">自评分数：{{searchEntity.SelfScore}}</van-col>       
      </van-row>
      <van-row>
      <van-col span="12">考评分数：{{searchEntity.OverScore}}</van-col>
      </van-row>
    </van-cell>
    <van-collapse v-model="activeNames">
      <div id="divInfo">
        <van-divider dashed>考核项</van-divider>
        <template v-for="(item,index) in listProject">
          <van-collapse-item v-bind:name="index+1" v-bind:key="index" icon="coupon-o">
            <template #title>
              <div class="checklist-title">
                {{item.AssessmentTarget}}
              </div>
            </template>
            <div id="divList">
              <template v-for="(itemGns,indexGns) in item.Grandsons">
                <div style="margin-bottom: 10px; padding-bottom: 10px" v-bind:key="indexGns">
                  <van-field v-bind:value="itemGns.ItemNo" v-bind:key="indexGns" style="display:none;"></van-field>
                  <van-row>
                    <van-col span="24">
                      <span class="spanPoint"> {{itemGns.GradingPoint}}（{{itemGns.Score}}分）</span>
                    </van-col>
                  </van-row>
                  <van-row>
                    <van-col span="24">
                      <span>评分标准：{{itemGns.GradingStandard}}</span>
                    </van-col>
                  </van-row>
                  <van-row>
                    <van-col span="24">
                      <span>自评分数：{{itemGns.SelfList[0].Score}}分</span>
                    </van-col>
                  </van-row>
                  <van-row>
                    <van-col span="24">
                      <span>加扣分说明：{{itemGns.SelfList[0].DeductRemark}}</span>
                    </van-col>
                  </van-row>
                  <van-row>
                    <van-col span="24">
                      <div style="margin-top:10px;" id="divFile">
                        <file-list-read-only :attachs="itemGns.SelfList[0].Attachs" :labelName="'自评附件：'"></file-list-read-only>
                      </div>
                    </van-col>
                  </van-row>
                  <div v-for="(itemGnsOther) in itemGns.OtherList">
                    <van-row>
                      <van-col span="12">
                        <span>考评人：{{itemGnsOther.UserOrDept}}</span>
                      </van-col>
                      <van-col span="12">
                        <span>考评分数：{{itemGnsOther.Score}}</span>
                      </van-col>
                    </van-row>
                    <van-row>
                      <van-col span="24">
                        <span>加扣分说明：{{itemGnsOther.DeductRemark}}</span>
                      </van-col>
                    </van-row>
                  </div>
                </div>
              </template>
            </div>
          </van-collapse-item>
        </template>
        <van-divider v-show="showTarget" dashed>指标项</van-divider>
        <template v-show="showTarget" v-for="(itemTarget,indexTarget) in listTarget">
          <van-collapse-item v-bind:name="itemTarget.IndexName" v-bind:key="itemTarget.ItemNo">
            <template #title>
              <img class="title-logo" src="@/assets/Images/AppIcon/fragment_noticetype_3.png" alt />
              {{itemTarget.IndexName}}
            </template>
            <div id="divList2">
              <van-field style="display:none;" v-bind:key="indexTarget" v-bind:name="itemTarget.IndexName" v-bind:value="itemTarget.ItemNo"></van-field>
              <van-row>
                <van-col span="12">
                  <span>指标值：{{itemTarget.SelfList[0].CalculateValue}}</span>
                </van-col>
                <van-col span="12">
                  <span>分数：{{itemTarget.Score}}</span>
                </van-col>
              </van-row>
              <van-row>
                <van-col span="24">
                  <span>评分标准：{{itemTarget.GradingStandard}}</span>
                </van-col>
              </van-row>
              <van-row>

                <van-col span="24">
                  <span>自评分数：{{itemTarget.SelfList[0].Score}}</span>
                </van-col>
              </van-row>
              <van-row>
                <van-col span="24">
                  <span> 加扣分说明：{{itemTarget.SelfList[0].DeductRemark}}</span>
                </van-col>
              </van-row>
              <van-row>
                <van-col span="24">
                  <div style="margin-top:10px;" id="divFile2">
                    <file-list-read-only :attachs="itemTarget.SelfList[0].Attachs" :labelName="'自评附件：'"></file-list-read-only>
                  </div>
                </van-col>
              </van-row>
              <div v-for="(itemTargetOther) in itemTarget.OtherList" v-bind:key="itemTargetOther.ItemNo">
                <van-row>
                  <van-col span="12">
                    <span>考评人：{{itemTargetOther.UserOrDept}}</span>
                  </van-col>
                  <van-col span="12">
                    <span>考评分数：{{itemTargetOther.Score}}</span>
                  </van-col>
                </van-row>
                <van-row>
                  <van-col span="24">
                    <span> 加扣分说明：{{itemTargetOther.DeductRemark}}</span>
                  </van-col>
                </van-row>
              </div>
            </div>
          </van-collapse-item>
        </template>
      </div>
    </van-collapse>
  </div>
</template>

<script>
import { findOtherDetail, otherUpdate } from "@/api/ZXTFAchievements";
import FileListReadOnly from "../../../components/Attach/FileListReadOnly.vue";
import { Col, Row } from 'vant';

export default {
  components: { Col, Row, FileListReadOnly },
  data() {
    return {
      List: [],
      searchEntity: { SelfScore: null },
      templateInfo: { TemplateScore: null, StandardScore: null },
      listProject: null,
      listTarget: null,
      show: false,
      activeNames: ["1"],
      id: this.$route.query.ID,
      showTarget:false
    };
  },
  created() {
    if (this.$route.query.ID) {
      this.getDetail();
    }
  },
  computed: {},
  methods: {
    getDetail() {
      var me = this;
      let params = { ID: this.id, type: 1 };
      findOtherDetail(params).then(res => {
        if (res != null && res.data != null) {

          me.searchEntity = res.data;
          me.templateInfo = res.data.TemplateInfo;
          me.listProject = res.data.TemplateInfo.Details;
          me.listTarget = res.data.TemplateInfo.Details2;
          if(me.listTarget!=null&&me.listTarget.length>0){
             me.showTarget=false;
          }else{
            me.showTarget=false;
          }
        }
      });
    },
    validator(val) {
      return true;
    },
    buttonSave(index) {
      var vm = this;
      var params = {};
      var saveProject = [];
      params.Details = [];
      params.Details3 = [];

      if (index == 1) {
        params.IsPublish = true;
        //  alert("提交");
      } else {
        params.IsPublish = false;
        //  alert("暂存");
      }
      params.ID = vm.searchEntity.ID;
      var isCheckOk = true;
      for (var i = 0; i < vm.listProject.length; i++) {

        for (var j = 0; j < vm.listProject[i].Grandsons.length; j++) {
          if (!isCheckOk) {
            continue;
          }
          var tempDetailPro = {};
          tempDetailPro.Code = vm.listProject[i].Grandsons[j].ItemNo;
          if (!vm.listProject[i].Grandsons[j].OtherList[0].Score) {
            isCheckOk = false;
            this.$dialog.alert({ message: "请输入【" + vm.listProject[i].AssessmentTarget + "-" + vm.listProject[i].Grandsons[j].GradingPoint + "】的考评分值", });
            return;
          }
          tempDetailPro.Score = vm.listProject[i].Grandsons[j].OtherList[0].Score;
          if (tempDetailPro.Score > vm.listProject[i].Grandsons[j].Score) {
            isCheckOk = false;
            this.$dialog.alert({ message: "考评分数不能大于设定分数!", });
            return;
          }
          tempDetailPro.DeductRemark = vm.listProject[i].Grandsons[j].OtherList[0].DeductRemark;
          params.Details.push(tempDetailPro);
        }
      }

      for (var i = 0; i < vm.listTarget.length; i++) {
        if (!isCheckOk) {
          return;
        }
        var tempDetailTarget = {};
        tempDetailTarget.Code = vm.listTarget[i].ItemNo;
        tempDetailTarget.CalculateValue = vm.listTarget[i].CalculateValue;
        if (!vm.listTarget[i].OtherList[0].Score) {
          isCheckOk = false;
          this.$dialog.alert({ message: "请输入【" + vm.listTarget[i].IndexName + "】的考评分值", });
          return;
        }

        tempDetailTarget.Score = vm.listTarget[i].OtherList[0].Score;
        if (tempDetailTarget.Score > vm.listTarget[i].Score) {
          isCheckOk = false;
          this.$dialog.alert({ message: "指标值【" + vm.listTarget[i].IndexName + "】的考评分数不能大于设定分数!", });
          return;
        }
        tempDetailTarget.DeductRemark = vm.listTarget[i].OtherList[0].DeductRemark;
        params.Details3.push(tempDetailTarget);
      }
      if (!isCheckOk) {
        return;
      };
      //自评
      otherUpdate(params).then(res => {
        if (params.IsPublish) {
          this.$toast.success("考评成功");

        } else {
          this.$toast.success("保存成功");
        }
        this.closePage();
      });
    },
    closePage() {
      if (window.jsListener || window.webkit) {
        if (window.jsListener) {
          window.jsListener.doBack();
        }
        if (window.webkit) {
          if (is_weixin()) {
            //如果是微信执行的操作
            _this.$router.goRefresh(-3);
          } else {
            //如果不是微信执行的操作
            if (window.webkit.messageHandlers) {
              window.webkit.messageHandlers.doBack.postMessage(2);
            }
          }
        }
      } else {
        this.$router.goRefresh();
      }
    }
  }
};
</script>


<style lang="less" scoped>
#divFile div {
  color: #646566;
}
#divFile2 div {
  color: #646566;
}
#divFileUpload .van-cell,
#divFileUpload1 .van-cell {
  background-color: transparent;
}

#divList .spanPoint,
#divList2 .spanPoint {
  font-size: 15px;
  color: black;
}

#divList span,
#divList2 span {
  color: #646566;
  font-size: 14px;
  line-height: 28px;
}
.van-col {
  vertical-align: middle;
}

.van-cell::after {
  border-bottom: 0px;
}
.van-field__label {
  width: 1.8rem;
  margin-right: 0px;
}
.total-count {
  display: flex;
  align-items: center;
}
.check-list {
  min-height: 100vh;
  padding-bottom: 100px;
  background-color: #e8f1f8;
}
.checklist-title {
  display: flex;
  align-items: center;
}
.title-logo {
  width: 15px;
  height: 16px;
  margin-right: 10px;
}
// 符合按钮
.accord-btns {
  display: flex;
  align-items: center;
  justify-content: space-between;
  .accord-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30%;
    height: 22px;
    background-color: #fff;
    color: #666;
    font-size: 12px;
  }
  .active {
    background-color: #1989fa;
    color: #fff;
  }
  .inconformity {
    background-color: #ee0a24;
    color: #fff;
  }
  .not-applicable {
    background-color: #ff976a;
    color: #fff;
  }
}
.inconformity-list {
  background-color: #fff;
  margin-top: 10px;
  padding-top: 10px;
}
/*
        .main {
            height: 100vh;
        }
    */

.det_top_box {
  padding: 10px;
  background-color: #e8f1f8;
}

.detail_header {
  color: #ffffff;
  background: url("../../../assets/Images/AppIcon/image_riskunit_detail_bg.png");
  background-size: cover;
  padding: 10px;
  border-radius: 5px;
  /*background-color: #fff;*/
}
.det_tab {
  padding: 10px;
  .det_tab_item {
    padding: 10px 0;
    background-color: #fff;
    border-radius: 5px;
    margin-bottom: 10px;

    .det_tab_item_text {
      padding: 0 10px;
    }
  }
}

.text_img {
  display: flex;
  align-items: center;

  .img_item {
    width: 33.3%;
    text-align: center;

    img {
      height: 25px;
      width: 25px;
      margin-bottom: 10px;
    }
  }
}

.text_total_img {
  display: flex;
  align-items: center;

  .img_item {
    width: 33.3%;
    text-align: center;

    .img_item_top {
      display: flex;
      vertical-align: middle;
      margin-bottom: 10px;
    }
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}

.bottom-buttons {
  width: 100%;
  position: fixed;
  bottom: 0;
  left: 0;
  .submit-button,
  .save-btn {
    border: none;
    border-radius: 0;
  }
  .submit-button {
    width: 70%;
  }
  .save-btn {
    width: 30%;
  }
}
.van-divider {
  border-color: #ccc;
}
</style>

<style lang="less">
.check-list {
  .van-collapse {
    .van-collapse-item__content {
      background-color: #e8f1f8;
      padding: 10px 10px 10px 10px;
    }
  }
}
</style>
